﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GoShopping.Model;

namespace GoShopping.BLL.PrdctInfo
{
    /// <summary>
    /// 特别推荐商品操作类
    /// </summary>
    public class RecomendPrdctBean
    {
        /// <summary>
        /// 静态类做缓存
        /// </summary>
        private static IList<RecomendPrdct> _AllRecomendPrdctList;

        /// <summary>
        /// 取出所有列表
        /// </summary>
        /// <returns></returns>
        public IList<RecomendPrdct> GetAll()
        {
            _AllRecomendPrdctList = Databases.DBGoShopping.Select(
                GoShoppingNBear.RecomendPrdct).ToList<RecomendPrdct>();
            return _AllRecomendPrdctList;
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        public void DelRecomendPrdct(int id)
        {
            Databases.DBGoShopping.Delete(
                GoShoppingNBear.RecomendPrdct).Where(
                GoShoppingNBear.RecomendPrdct.Prdctid == id).Execute();

            GetAll();
        }

        /// <summary>
        /// 添加一个
        /// </summary>
        /// <param name="dp"></param>
        public void AddOne(RecomendPrdct dp)
        {
            Databases.DBGoShopping.Insert(GoShoppingNBear.RecomendPrdct).AddColumn(
                GoShoppingNBear.RecomendPrdct.Prdctid, dp.Prdctid).AddColumn(
                GoShoppingNBear.RecomendPrdct.Reason, dp.Reason).Execute();
            GetAll();
        }

        /// <summary>
        /// 判断该商品是否是特别推荐商品
        /// </summary>
        /// <param name="prdctID"></param>
        /// <param name="RecomendPrdct"></param>
        /// <returns></returns>
        public bool IsRecomendPrdct(int prdctID, out RecomendPrdct RecomendPrdct)
        {
            if (_AllRecomendPrdctList == null)
            {
                GetAll();
            }
            foreach (RecomendPrdct d in _AllRecomendPrdctList)
            {
                if (d.Prdctid == prdctID)
                {
                    RecomendPrdct = d;
                    return true;
                }
            }
            RecomendPrdct = null;
            return false;
        }
    }
}
